package com.etone.smartAudit.mapstruct;

import com.etone.smartAudit.domain.IapDataModel;
import com.etone.smartAudit.dto.iapDataModel.IapDataModelDTO;
import com.etone.smartAudit.vo.iapDataModel.IapDataModelDetailVO;
import org.mapstruct.*;

/**
 * @author: sovy
 * @date: 2020/8/28
 * @description:
 */
@Mapper(componentModel = "spring",imports = {org.springframework.util.CollectionUtils.class,com.alibaba.fastjson.JSON.class,org.springframework.util.StringUtils.class,com.etone.smartAudit.vo.FileVO.class,com.etone.smartAudit.utils.StringUtil.class})
public interface IapDataModelMapstruct {
    @Mappings({
            @Mapping(target = "dataExamples", expression = "java(StringUtils.isEmpty(iapDataModel.getDataExamples())?null: JSON.parseArray(iapDataModel.getDataExamples(),FileVO.class))"),

            @Mapping(target = "dataAssertIds", expression = "java(StringUtil.intToList(iapDataModel.getDataAssertIds()))"),
            @Mapping(target = "dataAssertNames", expression = "java(StringUtil.stringToList(iapDataModel.getDataAssertNames()))"),

            @Mapping(target = "autoTagIds", expression = "java(StringUtil.intToList(iapDataModel.getAutoTagIds()))"),
            @Mapping(target = "autoTagNames", expression = "java(StringUtil.stringToList(iapDataModel.getAutoTagNames()))"),

            @Mapping(target = "dataMassIds", expression = "java(StringUtil.intToList(iapDataModel.getDataMassIds()))"),
            @Mapping(target = "dataMassNames", expression = "java(StringUtil.stringToList(iapDataModel.getDataMassNames()))"),

            @Mapping(target = "dimensionIds", expression = "java(StringUtil.intToList(iapDataModel.getDimensionIds()))"),
            @Mapping(target = "dimensionNames", expression = "java(StringUtil.stringToList(iapDataModel.getDimensionNames()))")
    })
    IapDataModelDetailVO getIapDataModelDetailVO(IapDataModel iapDataModel);


    @Mappings({
            @Mapping(target = "dataExamples", expression = "java(CollectionUtils.isEmpty(iapDataModelDTO.getDataExamples())?\"[]\":JSON.toJSONString(iapDataModelDTO.getDataExamples()))")
    })
    void copyIapDataModel(@MappingTarget IapDataModel iapDataModel, IapDataModelDTO iapDataModelDTO);
}
